"""backend URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.conf.urls.static import static
from django.urls import path, include
from drf_spectacular.views import (
    SpectacularAPIView,
    SpectacularRedocView,
    SpectacularSwaggerView,
)
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
    TokenVerifyView,
)

from application import settings
from core.schema  import CustomSchemaGenerator

urlpatterns = [
    path("admin/", admin.site.urls),
    # OpenAPI 3.0 架构端点
    path(
        "schema/",
        SpectacularAPIView.as_view(generator_class=CustomSchemaGenerator),
        name="schema",
    ),
    
    # Swagger UI 界面
    path(
        "",
        SpectacularSwaggerView.as_view(url_name='schema'),
        name="swagger-ui",
    ),
    
    # ReDoc 界面
    path(
        "redoc/",
        SpectacularRedocView.as_view(url_name='schema'),
        name="redoc",
    ),
    
    # DRF 认证端点
    path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
    
    # JWT 认证端点
    path('token/', TokenObtainPairView.as_view(),  name='token_obtain'),
    path('token/refresh/', TokenRefreshView.as_view(),  name='token_refresh'),
    path('token/verify/', TokenVerifyView.as_view(),  name='token_verify'),
    
    # 应用路由
    path("sys/", include("apps.sys.urls")),
    path("pms/", include("apps.pms.urls")),
    path("tms/", include("apps.tms.urls")),
    path("rms/", include("apps.rms.urls")),
    path("oms/", include("apps.oms.urls")),
    path("dms/", include("apps.dms.urls")),
    path("tools/", include("apps.tools.urls")),
]

# 静态文件和媒体文件服务
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
